package com.yyfax.ph.personal.mymoney.cash;

import com.yyfax.common.CLog;
import com.yyfax.infrastructure.eventbus.EventAgent;
import com.yyfax.infrastructure.mvp.Model;
import com.yyfax.infrastructure.network.NetworkHelper;
import com.yyfax.infrastructure.network.entity.BaseResultEntity;
import com.yyfax.ph.base.YJPH;
import retrofit2.http.Body;
import retrofit2.http.Header;
import retrofit2.http.POST;
import rx.Observable;

import java.util.List;

public class RebateDetailModel extends Model {
	private static final String TAG = RebateDetailModel.class.getSimpleName();

	protected static final int MSG_REFRESH_REBATE_DETAILS = 6;
	protected static final int MSG_LOAD_MORE_REBATE_DETAILS = 7;

	@Override
	public Observable getObservable(Object params, int functionalCode) {
		Service service = (Service) NetworkHelper.createService(Service.class);
		String token = YJPH.getInstance().getPreferenceManager().getLoginToken();
		return service.getRebateList(token, (RebateParams) params);
	}

	@Override
	public void onNext(Object obj) {
		CLog.i(TAG, "onNext: " + obj.toString());
		RebateDetailResult result = cast(obj);
		EventAgent.post(result);
	}

	private interface Service {
		@POST("account/balance/cashbackDetail")
		Observable<RebateDetailResult> getRebateList(@Header("token") String token, @Body RebateParams params);
	}

	public static class RebateParams {
		/**
		 * 当页码
		 */
		public int pageNo;
		/**
		 * 页长
		 */
		public int pageSize;
		/**
		 * 开始时间(yyyy/mm/dd)
		 */
		public String startDate;

	}

	public static class RebateInfo {
		/***
		 * 推荐日期
		 */
		public String operateDate;
		/***
		 * 返佣
		 */
		public String amount;
		/***
		 *借款人
		 */
		public String customerName;
		/***
		 * 放款金额
		 */
		public String businesssum;
	}

	public static class RebateDetail {
		/***
		 * 返现笔数
		 */
		public int cnt;
		/***
		 * 返现总额
		 */
		public int amountSum;

		public List<RebateInfo> accountDetailForDrawList;

	}

	static class RebateDetailResult extends BaseResultEntity<RebateDetail> {
	}
}
